<script>
import { loadVipinfo, getInfo } from "@/api/user/user.js";
// import TencentIM from "@/util/TencentIM.js";
import {
		EventBus
	} from "@/util/event-bus.js";

export default {
  globalData: {
    userInfo: {},
    vipInfo: {}, 
  },
  onLaunch: function () {
    console.log("App Launch");
    // uni.hideTabBar()
	if (uni.getStorageSync("token")) {
		this.requestUserInfo();
		let userInfo = uni.getStorageSync("userInfo") || {};
		this.globalData.userInfo = userInfo;
	} else {
		uni.setStorageSync("userInfo",{});
		this.globalData.userInfo = {};
	}
	
	let that = this;
	EventBus.$on('loginSuccess', function(res) {
		that.requestUserInfo()
	});
  },
  onShow: function () {
    console.log("App Show");
    // let userInfo = uni.getStorageSync("userInfo");
    // if (userInfo) {
    //   TencentIM.login();
    // }
  },
  onHide: function () {
    console.log("App Hide");
  },
  methods: {
	  requestUserInfo(){
		  this.loadVipInfoAction();
		  this.getInfoAction();
	  },
    loadVipInfoAction() {
      let vipInfo = uni.getStorageSync("vipInfo") || {};
      this.globalData.vipInfo = vipInfo;
      loadVipinfo().then((res) => {
        if (res.status == 1) {
          uni.setStorageSync("vipInfo", res.data);
          this.globalData.vipInfo = res.data;
          console.log(
            "this.globalData.vipInfo-------=",
            this.globalData.vipInfo
          );
        }
      });
    },
    getInfoAction() {
	 let that = this;
      getInfo().then((res) => {
        if (res.status == 1) {
          uni.setStorageSync("userInfo", res.data || {});
          that.globalData.userInfo = res.data;
        }
      });
    },
  },
};
</script>

<style lang="scss">
@import "uview-ui/index.scss";
@import "./static/css/global.css";
@import "./static/css/iconfont.css";

/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
  font-family: uniicons;
  src: url("/static/uni.ttf");
}

/* #endif */
view {
  box-sizing: border-box;
}
page {
  background: #f3f6f8;
}
::-webkit-scrollbar {
    display: none;
    width: 0 !important;
    height: 0 !important;
    -webkit-appearance: none;
    background: transparent;
    color: transparent;
  }
</style>
